package appname.example.com.testmvvm;

import android.support.v7.util.DiffUtil;

import java.util.ArrayList;

public class MyDeffutilCallback extends DiffUtil.Callback {

    private ArrayList<Testbean> mOldData, mnewData;

    public MyDeffutilCallback(ArrayList<Testbean> mOldData, ArrayList<Testbean> mnewData) {
        this.mOldData = mOldData;
        this.mnewData = mnewData;
    }

    @Override
    public int getOldListSize() {
        return mOldData != null ? mOldData.size() : 0;
    }

    @Override
    public int getNewListSize() {
        return mnewData != null ? mnewData.size() : 0;
    }


    @Override
    public boolean areItemsTheSame(int i, int i1) {
      return mOldData.get(i).getName().equals(mnewData.get(i1).getName());

    }

    @Override
    public boolean areContentsTheSame(int i, int i1) {
        Testbean olddata = mOldData.get(i);
        Testbean newdata = mnewData.get(i1);
        if (!olddata.getName().equals(newdata.getName())) {
            return false;
        } else if (!olddata.getName1().equals(newdata.getName1())) {
            return false;
        } else if (!olddata.getName2().equals(newdata.getName2())) {
            return false;
        } else if (!olddata.getName3().equals(newdata.getName3())) {
            return false;
        } else {
            return true;
        }
    }
}
